<?php

/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Sitealbum
 * @copyright  Copyright 2010-2011 BigStep Technologies Pvt. Ltd.
 * @license    http://www.socialengineaddons.com/license/
 * @version    $Id: IndexController.php 2011-08-026 9:40:21Z SocialEngineAddOns $
 * @author     SocialEngineAddOns
 */
class Sitealbum_IndexController extends Core_Controller_Action_Standard {

  public function indexAction() {
    if (!$this->_helper->requireAuth()->setAuthParams('album', null, 'view')->isValid())
      return;
    $getLightBox = Zend_Registry::isRegistered('sitealbum_getajaxview') ? Zend_Registry::get('sitealbum_getajaxview') : null;
    if (empty($getLightBox)) {
      return;
    }
    $this->_helper->content
            ->setNoRender()
            ->setEnabled()
    ;
  }

//ACTION FOR UNHIDE THE PHOTO
  public function unhidePhotoAction() {
    // CHECK USER VALIDATION
    if (!$this->_helper->requireUser()->isValid())
      return;

    //SET LAYOUT
    $this->_helper->layout->setLayout('default-simple');

    //UNHIDE PHOTO FORM
    $this->view->form = $form = new Sitealbum_Form_Unhidephoto();

    //CHECK FORM VALIDAITON
    if ($this->getRequest()->isPost() && $form->isValid($this->getRequest()->getPost())) {

      $table = Engine_Api::_()->getItemTable('album_photo')->update(array('photo_hide' => 0), array('owner_id = ?' => $this->_getParam('user_id', null), 'photo_hide = ?' => 1));
      $this->_forward('success', 'utility', 'core', array(
          'smoothboxClose' => true,
          'parentRefresh' => true,
          'format' => 'smoothbox',
          'messages' => array(Zend_Registry::get('Zend_Translate')->_('Your photos have been restored.'))
      ));
    }
  }

  public function taggedUserAction() {
    if (0 == ($album_id = (int) $this->_getParam('album_id')) ||
            null == ($album = Engine_Api::_()->getItem('album', $album_id))) {
      return $this->_forward('notfound', 'error', 'core');
    }

    if (!$this->_helper->requireAuth()->setAuthParams($album, null, 'view')->isValid())
      return;
    $this->view->insideAlbum = $inSideAlbum = Engine_Api::_()->sitealbum()->getTaggedUser($album_id);
    $this->view->viewer = $this->view->viewer();
  }

  public function youAndOwnerPhotosAction() {
    // Check auth
    if (!$this->_helper->requireUser()->isValid())
      return;

    if (0 == ($owner_id = (int) $this->_getParam('owner_id')) ||
            null == ($owner = Engine_Api::_()->getItem('user', $owner_id))) {
      return $this->_forward('notfound', 'error', 'core');
    }
    $viewer = Engine_Api::_()->user()->getViewer();
    $viewer_id = $viewer->getIdentity();
    $this->view->owner = $owner;

    $this->view->youAndOwner = $youAndOwner = Engine_Api::_()->sitealbum()->getTaggedYouAndOwnerPhotos($viewer_id, $owner_id);
    $youAndOwner->setItemCountPerPage(100);
    $youAndOwner->setCurrentPageNumber($this->_getParam('page', 1));

    $this->view->showLightBox = Engine_Api::_()->sitealbum()->showLightBoxPhoto();
  }

// ACTION FOR FEATURED PHOTOS CAROUSEL AFTER CLICK ON BUTTON 
  public function featuredPhotosCarouselAction() {
     $this->_helper->layout->disableLayout();
    //RETRIVE THE VALUE OF ITEM VISIBLE
    $this->view->itemsVisible = $limit = (int) $_GET['itemsVisible'];

    //RETRIVE THE VALUE OF NUMBER OF ROW
    $this->view->noOfRow = (int) $_GET['noOfRow'];
    //RETRIVE THE VALUE OF ITEM VISIBLE IN ONE ROW
    $this->view->inOneRow = (int) $_GET['inOneRow'];

    // Total Count Featured Photos
    $totalCount = (int) $_GET['totalItem'];

    //RETRIVE THE VALUE OF START INDEX
    $startindex = $_GET['startindex'] * $limit;

    if ($startindex > $totalCount) {
      $startindex = $totalCount - $limit;
    }
    if ($startindex < 0)
      $startindex = 0;

    //RETRIVE THE VALUE OF BUTTON DIRECTION
    $direction = $_GET['direction'];
    $this->view->offset = $values['start_index'] = $startindex;

    //GET Featured Photos with limit * 2
    $this->view->totalItemsInSlide = $values['limit'] = $limit * 2;
    $this->view->featuredPhotos = $featuredPhotos = Engine_Api::_()->sitealbum()->getFeaturedPhotos($values);

    //Pass the total number of result in tpl file
    $this->view->count = count($featuredPhotos);

    //Pass the direction of button in tpl file
    $this->view->direction = $direction;
    $this->view->showLightBox = Engine_Api::_()->sitealbum()->showLightBoxPhoto();
    if ($this->view->showLightBox) {
      $this->view->params = $params = array('type' => 'featured', 'count' => $totalCount);
    }
  }

}
?>
